import {
  Inject,
  Controller,
  Post,
  Put,
  Del,
  Get,
  Param,
  File,
  Body,
  Queries
} from "@midwayjs/core";
import { Context } from "@midwayjs/koa";
import { Utils } from "../utils/index";
import { RecordService } from "../service/record.service";
import { RecordCreateDto, RecordPageQueryDto } from "../dto/record.dto";
import { UploadFileInfo } from "@midwayjs/upload";

@Controller()
export class RecordController {
  @Inject()
  ctx: Context;

  @Inject()
  recordService: RecordService;

  @Inject()
  utils: Utils;

  @Post("/app-api/record", { summary: "app添加球杆验证档案" })
  async app_add_record(@Body() dto: RecordCreateDto) {
    const result = await this.recordService.add_record(dto);
    return this.utils.response.success({
      ...result
    });
  }

  @Post("/auth-api/record", { summary: "添加球杆验证档案" })
  async add_record(@Body() dto: RecordCreateDto) {
    const result = await this.recordService.add_record(dto);
    return this.utils.response.success({
      ...result
    });
  }

  @Put("/auth-api/record/:recordId", { summary: "更新球杆验证档案" })
  async update_record(
    @Param("recordId") recordId: string,
    @Body() dto: RecordCreateDto
  ) {
    const result = await this.recordService.update_record(recordId, dto);
    return this.utils.response.success({
      ...result
    });
  }
  @Del("/auth-api/record/:recordId", { summary: "删除球杆验证档案" })
  async delete_record(@Param("recordId") recordId: string) {
    const result = await this.recordService.delete_record(recordId);
    return this.utils.response.success({
      ...result
    });
  }

  @Get("/auth-api/record/page", { summary: "获取球杆验证档案分页列表" })
  async get_record_page_list(@Queries() dto: RecordPageQueryDto) {
    const result = await this.recordService.get_record_page_list(dto);
    return this.utils.response.success({
      ...result
    });
  }

  @Post("/auth-api/record/upload", { summary: "批量上传球杆验证档案" })
  async batch_upload_record(@File() file: UploadFileInfo<any>) {
    const result = await this.recordService.batch_upload_record_new(file);
    return this.utils.response.success({
      ...result
    });
  }

  @Get("/common-api/record/:recordCode", { summary: "检查球杆编号是否存在" })
  async check_record_exist(@Param("recordCode") recordCode: string) {
    const result = await this.recordService.check_record_exist(recordCode);
    if (result.success) {
      return this.utils.response.success({
        ...result
      });
    } else {
      return this.utils.response.fail({
        ...result
      });
    }
  }
}
